var myClock = new Clock();
var alarmArray = [];

window.onload = function () {
	myClock.startCycle(1000,function() {
			updateClock();
		}
	);
	
	populateAlarmBoxes();
};

function populateAlarmBoxes()
{
	hourBox = "";
	for(var i = 0; i < 24; i++)
	{
		if(i < 10)
		{
			hourBox += "<option>0" + i + "</option>";
		}
		else
		{
			hourBox += "<option>" + i + "</option>";
		}
	}
	document.getElementById("hourSelect").innerHTML = hourBox;
	
	minBox = "";
	for(var i = 0; i < 60; i++)
	{
		if(i < 10)
		{
			minBox += "<option>0" + i + "</option>";
		}
		else
		{
			minBox += "<option>" + i + "</option>";
		}
	}
	
	document.getElementById("minSelect").innerHTML = minBox;
	
}

	
function updateClock()
{
	document.getElementById("clockDisplay1").innerHTML = myClock.currentTime.outputTime();
}

function addAlarm()
{
	var thisAlarm = new Alarm();
	thisAlarm.createAlarm(myClock.currentTime,document.getElementById("addAlarmInput").value,alarmSound);
	alarmArray.push(thisAlarm);
	getAlarms();
}

function addAlarm_New()
{
	var thisAlarm = new Alarm();
	var alarmTime = document.getElementById("hourSelect").options[document.getElementById("hourSelect").selectedIndex].text + document.getElementById("minSelect").options[document.getElementById("minSelect").selectedIndex].text + "00";
	
	alert(alarmTime);
	thisAlarm.createAlarm(myClock.currentTime,alarmTime,alarmSound);
	alarmArray.push(thisAlarm);
	getAlarms();
}

function getAlarms()
{
	var displayElement = document.getElementById("alarmDisplay");
	var alarmDisplayContent = "";
	displayElement.length = 0;
	
	for(var i = 0; i < alarmArray.length; i++)
	{
		alarmDisplayContent += "<option>" + alarmArray[i].alarmTime.outputTime() + "</option>";
	}
	displayElement.innerHTML = alarmDisplayContent;
}

function alarmSound(thisAlarm)
{
	alert("This alarm is sounding! \n\n " + thisAlarm.alarmTime.outputTime());
	
	//Any other alarm sounding code. Alarm passed back as thisAlarm
}